package com.example.a22310.myapplication.ViewModel.Master;

import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.example.a22310.myapplication.Activity.ConsultActivity;
import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Listener.ClubListener;
import com.example.a22310.myapplication.Model.ClubModel;
import com.example.a22310.myapplication.databinding.ActivityMasterDetailBinding;

import java.util.List;

public class MasterDetailViewModel implements ClubListener<MediaStore.Video> {
    private ActivityMasterDetailBinding binding;
    private AppCompatActivity activity;
    private int clubid;
    private String  clubname;
    public static  int  NEWSFLAG;



    public MasterDetailViewModel(AppCompatActivity activity, ActivityMasterDetailBinding binding,int club_id,String  clubname){
        this.activity = activity;
        this.binding = binding;
        this.clubid = club_id;
        this.clubname = clubname;
        binding.setMaster(this);
        ClubModel clubModel=new ClubModel();
        clubModel.videolist(club_id,MasterDetailViewModel.this);

    }

    public void back(View view ){
        activity.onBackPressed();
    }

    public void reqeust(View view ){
        Intent intent = new Intent(activity, ConsultActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt("aa",1);
        NEWSFLAG = 0;
        bundle.putString("clubName",clubname);
        activity.startActivity(intent);
    }


    @Override
    public void onSuccess(MediaStore.Video video) {
        if(video.getCode()!=404){
            List<MediaStore.Video.ClubvideolistBean> clubvideolistBeen =  video.getClubvideolist();
            binding.recyclerViewMaster.setLayoutManager(new LinearLayoutManager(activity));
            MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_master_video,
                    clubvideolistBeen, BR.videos);
            binding.recyclerViewMaster.setAdapter(adapter);

        }

    }

    @Override
    public void onFailure() {
    }
}
